<?php $view->extend('::base.html.php') ?>
<?php echo $view['actions']->render('AcmeTest:Index:listMenu', array('listid' => $listid, 'routeName' => $app->getRequest()->attributes->get('_route'))); ?>
<?php echo $view->render('RMDAccountBundle::flashMessages.html.php') ?>
<h3><?php echo $listTitle; ?></h3>
<?php
if ($subscribers->count()) :
?>
<form action="<?php echo $view['router']->generate('account_subscribers_add', array('listid' => $listid)) ?>" method="post" <?php echo $view['form']->enctype($form) ?>>
<table border="1">

	<tr>
		<td>
		<?php echo $view['form']->widget($form['firstname']); ?>
		</td>
		<td>
		<?php echo $view['form']->widget($form['lastname']); ?>
		</td>
		<td>
		<?php echo $view['form']->widget($form['email']); ?>
		</td>
		<td colspan="2">
			<input type="submit" class="btn" value="Quick add"/>
		</td>
		<td colspan="2">
			<a class="btn btn-primary btn-large" href="<?php echo $view['router']->generate('account_subscribers_add', array('listid' => $listid)); ?>">Subscribe</a>
		</td>
	</tr>
	<tr>
		<th>First name</th>
		<th>Last name</th>
		<th>Email address</th>
		<?php foreach ($groupSets as $grpSet): ?>
			<th><?php echo $grpSet->getTitle(); ?></th>
		<?php endforeach; ?>		
		<th>Subscription source</th>
		<th>Subscription date</th>
		<th colspan="2">Modify</th>
	</tr>
	<?php 
		foreach ($subscribers as $subscriber) :
	?>
	<tr>
		<td>
			<?php echo $subscriber->getFirstname(); ?>
		</td>
		<td>
			<?php echo $subscriber->getLastname(); ?>
		</td>
		<td>
			<?php echo $subscriber->getEmail(); ?>
		</td>
		<?php foreach ($groupSets as $grpSet): ?>
			<td>
				<?php
					$titles = array();
					foreach ($grpSet->getGroups() as $grp) {
						if ($subscriber->isInGroup($grp)) {
							$titles[] = $grp->getTitle();
						}
					}
					echo implode(', ', $titles);
				 ?>
			</td>
		<?php endforeach; ?>		
		<td>
			<?php echo $subscriber->getSignedFrom(); ?>
		</td>
		<td>
			<?php echo $subscriber->getDateSigned()->format('Y-m-d H:i:s'); ?>
		</td>
		<td>
			<a class="btn" href="<?php echo $view['router']->generate('account_subscribers_edit', array('id' => $subscriber->getId())); ?>">Edit</a>
		</td>
		<td>
			<a class="btn" href="<?php echo $view['router']->generate('account_subscribers_delete', array('id' => $subscriber->getId())); ?>">Delete</a>
		</td>

	</tr>
	<?php	
		endforeach;
	?>
</table>
<?php echo $view['form']->widget($form['_token']); ?>
</form>
<?php
else :
?>
	<div>
		There are no subscribers in this list.<br/>
		<a href="<?php echo $view['router']->generate('account_subscribers_add', array('listid' => $listid)); ?>">Add one</a>
	</div>
<?php
endif;
?>
